<% redcar_css = File.expand_path(File.join(Redcar.root, %w(plugins html_view views default.css))) %>
<% watermark  = File.expand_path(File.join(Redcar.root, %w(plugins html_view views watermark-48.png))) %>
<link rel="stylesheet" href="file://<%= redcar_css %>" type="text/css" media="screen">
<div id="top">
  <img src="file://<%=watermark%>" id="watermark"/>
  <h1>Task Manager</h1>
  <a href="controller/index">Refresh</a>
</div>
<div class="main">
<h4>Pending</h4>

<table>
  <tr>
    <th>Enqueued</th>
    <th>Description</th>
  </tr>
  <% Redcar.app.task_queue.pending.each do |task| %>
    <tr>
      <td><%= task.enqueue_time.strftime("%X") %></td>
      <td><%= CGI.escapeHTML(task.description || task.class.to_s) %></td>
    </tr>
  <% end %>
</table>

<h4>In Process</h4>

<table>
  <tr>
    <th>Started</th>
    <th>Description</th>
  </tr>
  <% if task = Redcar.app.task_queue.in_process %>
    <tr>
      <td><%= task.start_time.strftime("%X") %></td>
      <td><%= CGI.escapeHTML(task.description || task.class.to_s) %></td>
    </tr>
  <% end %>
</table>

<h4>Completed</h4>

<table>
  <tr>
    <th>Completed</th>
    <th>Description</th>
    <th>Duration</th>
  </tr>
  <% Redcar.app.task_queue.completed.reverse.each do |task| %>
    <tr class="<%= "error" if task.error %>">
      <td><%= task.completed_time.strftime("%X") %></td>
      <td><%= CGI.escapeHTML(task.description || task.class.to_s) %></td>
      <td><%= task.completed_time - task.start_time %></td>
    </tr>
    <% if e = task.error %>
      <tr>
        <td colspan="3">
          <strong><%= e.class %></strong>
          <%= CGI.escapeHTML(e.message) %>
          <br /><br />
          <% e.backtrace.each do |line| %>
            <%= line %><br />
          <% end %>
        </td>
      </tr>
    <% end %>
  <% end %>
</table>
</div>


